﻿package com.tangchao.client.sdh.view.role
{
	import com.tangchao.client.entities.User;
	import com.tangchao.client.sdh.definition.DFRolePlace;
	import com.tangchao.client.sdh.definition.DFSuoFangDaXiao;
	import com.tangchao.client.sdh.event.ClickRoleEvent;
	import com.tangchao.client.sdh.vo.Player;
	import com.tangchao.client.sdh.vo.RoleInfoVo;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	public class RoleGrid extends MovieClip
	{
		private var _show:RoleShow;
		private var _upRole:UpRole;
		private var _rightRole:RightRole;
		private var _leftRole:LeftRole;
		private var _myPos:int;
		private var _mcMask:MovieClip;
		
		public function RoleGrid()
		{
			init();
		}
		
		private function init()
		{
			_show=getChildByName("mcShow") as RoleShow;
			_show.addEventListener(MouseEvent.CLICK,onShowClick);
			_upRole=getChildByName("mcUpRole") as UpRole;
			_rightRole=getChildByName("mcRightRole") as RightRole;
			_leftRole=getChildByName("mcLeftRole") as LeftRole;
			addEventListener(ClickRoleEvent.CLICK_ROLE,onClickRoleEvent);
			
			_mcMask = getChildByName("mcMask") as MovieClip;
			_mcMask.stop();
			
			_leftRole.visible=false;
			_rightRole.visible=false;
			_upRole.visible=false;
		}
		
		/*
		*创建或隐藏左边角色
		*/
		public function leftRoleIn(v:Player)
		{
			if(v)
			{
				_leftRole.visible=true;
				_leftRole.create(v);
				v.ui = _leftRole;
			}
			else
			{
				_leftRole.visible=false;
			}
		}
		
		/*s
		*创建或隐藏右边角色
		*/
		public function rightRoleIn(v:Player)
		{
			if(v)
			{
				_rightRole.visible=true;
				_rightRole.create(v);
				v.ui = _rightRole;
			}
			else
			{
				_rightRole.visible=false;
			}
		}
		
		/*
		*创建或隐藏上边角色
		*/
		public function upRoleIn(v:Player)
		{
			if(v)
			{
				_upRole.visible=true;
				_upRole.create(v);
				v.ui = _upRole;
			}
			else
			{
				_upRole.visible=false;
			}
		}
		
		private function onClickRoleEvent(e:ClickRoleEvent)
		{
			_show.visible=true;
			_show.create(e.vo);
			switch(e.place)
			{
				case DFRolePlace.PLACE_LEFT:
					_show.x=80;
					_show.y=193;
					break;
				case DFRolePlace.PLACE_RIGHT:
					_show.x=696;
					_show.y=332;
					break;
				case DFRolePlace.PLACE_UP:
					_show.x=370;
					_show.y=80;
					break;
			}
		}
		
		private function onShowClick(e:MouseEvent)
		{
			_show.visible=false;
		}
		
		public function setViewPos(viewPos:int):void
		{
			switch(viewPos)
			{
				case DFSuoFangDaXiao.ZHONG:
					_mcMask.gotoAndStop(1);
					_upRole.setViewPos(viewPos);
					_leftRole.setViewPos(viewPos);
					_rightRole.setViewPos(viewPos);
					break;
				case DFSuoFangDaXiao.JIN:
					_mcMask.gotoAndStop(2);
					_upRole.setViewPos(viewPos);
					_leftRole.setViewPos(viewPos);
					_rightRole.setViewPos(viewPos);
					break;
				case DFSuoFangDaXiao.YUAN:
					_mcMask.gotoAndStop(3);
					_upRole.setViewPos(viewPos);
					_leftRole.setViewPos(viewPos);
					_rightRole.setViewPos(viewPos);
					break;
				default:
					break;
			}
		}
	}
}